package com.tbit.main.service.impl;

import com.tbit.main.constant.DaoParamConstant;
import com.tbit.main.dao.core.SuggestionDao;
import com.tbit.main.pojo.Suggestion;
import com.tbit.main.service.SuggestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("suggestionService")
public class SuggestionServiceImpl implements SuggestionService {
    @Autowired
    private SuggestionDao suggestionDao;

    @Override
    public void update(Suggestion suggestion) {
        suggestionDao.update(suggestion);
    }

    @Override
    public List<Suggestion> query(Integer accountId, Integer state, String startTime, String endTime) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(DaoParamConstant.accountId, accountId);
        params.put("state", state);
        params.put(DaoParamConstant.startTime, startTime);
        params.put(DaoParamConstant.endTime, endTime);

        return suggestionDao.query(params);
    }

    @Override
    public Integer queryContent(Integer accountId, Integer state, String startTime, String endTime) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(DaoParamConstant.accountId, accountId);
        params.put("state", state);
        params.put(DaoParamConstant.startTime, startTime);
        params.put(DaoParamConstant.endTime, endTime);

        return suggestionDao.queryContent(params);
    }

    @Override
    public List<Suggestion> queryPage(Integer accountId, Integer state, String startTime, String endTime, Integer rowCount, Integer pageNO) {
        Map<String, Object> params = new HashMap<>();
        params.put(DaoParamConstant.accountId, accountId);
        params.put("state", state);
        params.put(DaoParamConstant.startTime, startTime);
        params.put(DaoParamConstant.endTime, endTime);
        params.put("start", (pageNO - 1) * rowCount);
        params.put("rowCount", rowCount);

        return suggestionDao.queryPage(params);
    }

    @Override
    public Suggestion getBySuggestionId(Integer suggestionId) {
        return suggestionDao.getBySuggestionId(suggestionId);
    }

}  